home *** CD-ROM | disk | FTP | other *** search
/ Aminet 23 / Aminet 23 (1998)(GTI - Schatztruhe)[!][Feb 1998].iso / Aminet / util / cli / move37.lha / Move37 / move.c next >
Encoding:
C/C++ Source or Header  |  1997-11-02  |  2.3 KB  |  109 lines

  1. /* 
  2. **
  3. **    Move.c - (C) 1993-97 by Stephan Rupprecht
  4. **    a move command for AmigaDOS
  5. **
  6. **    COMPILER
  7. **    MaxonC++ 4
  8. **
  9. **    LINKER-OPTIONS
  10. **    small data-/code, no startup-code
  11. **
  12. **    HISTORY
  13. **    Nov-1993 first release
  14. **    Nov-1994 update
  15. **    Okt-1997 rewritten
  16. **    Nov-1997 bugfix, added 'AS' option
  17. **
  18. */
  19.  
  20. #include <dos/dos.h>
  21. #include <dos/dosextens.h>
  22.  
  23. #include <pragma/dos_lib.h>
  24. #include <pragma/exec_lib.h>
  25.  
  26. /****************************************************************************/
  27.  
  28. STRPTR VerStr = "\0$VER: move 37.1 ("__DATE2__") © 1997 by Stephan Rupprecht";
  29. struct Library    *DOSBase;
  30.  
  31. void sprintf(STRPTR PutChData, STRPTR FormatStr, ...);
  32.  
  33. /****************************************************************************/
  34.  
  35. LONG main(void)
  36. {     
  37.     LONG ret = RETURN_FAIL;
  38.     
  39.     GetBaseReg();
  40.     
  41.     if(DOSBase = OpenLibrary("dos.library", 37L))
  42.     {        
  43.         static struct { STRPTR src, dst; LONG as; } args = { 0L, 0L, DOSFALSE };
  44.         struct RDArgs *rdargs;
  45.         STRPTR    p;
  46.         TEXT dst[256];            
  47.         
  48.         if(rdargs = ReadArgs("FILE/A,TO/A,AS/S", (LONG *)&args, 0))
  49.         {    
  50.             p = PathPart(args.src);
  51.             if((*p == '/') && (*(p+1) == '\0')) *p = '\0';
  52.             
  53.             p = args.src;            
  54.             strncpy(dst, args.dst, sizeof(dst));
  55.             
  56.             if(args.as == DOSFALSE)
  57.             {                
  58.                 if(!(AddPart(dst, FilePart(p), sizeof(dst))))
  59.                 {
  60.                     SetIoErr(ERROR_LINE_TOO_LONG);
  61.                     goto err;
  62.                 }
  63.             }
  64.                                             
  65.             if(Rename(p, dst) == DOSFALSE)
  66.             {
  67.                 LONG err = 0L;
  68.                 
  69.                 if((err = IoErr()) == ERROR_RENAME_ACROSS_DEVICES)
  70.                 {
  71.                     TEXT cmd[256];
  72.                 
  73.                     sprintf(cmd, "Copy \"%s\" TO \"%s\" CLONE QUIET ALL", p, dst);
  74.                 
  75.                     if(!System(cmd, NULL))
  76.                     {
  77.                         sprintf(cmd, "Delete >NIL: \"%s\" QUIET ALL FORCE", p);
  78.                         
  79.                         if(!System(cmd, NULL))
  80.                             ret = RETURN_OK;
  81.                     }
  82.                 }
  83.                 else SetIoErr(err);
  84.             }
  85.             else ret = RETURN_OK;
  86. err:            
  87.             FreeArgs(rdargs);
  88.         }
  89.         
  90.         if(ret != RETURN_OK) PrintFault(IoErr(), "Move");
  91.         else Printf("Moved %s to %s\n", p, dst);
  92.         
  93.         CloseLibrary(DOSBase);
  94.     }
  95.     
  96.     return(ret);
  97. }
  98.  
  99. /****************************************************************************/
  100.  
  101. void sprintf(STRPTR PutChData, STRPTR FormatStr, ...)
  102. {
  103.     static ULONG PutChProc = 0x16c04e75;
  104.     
  105.     RawDoFmt(FormatStr, ((STRPTR)(&FormatStr))+4, (void (*)())&PutChProc, PutChData);
  106. }
  107.  
  108. /****************************************************************************/
  109.